//
//  MineDingDanCell.swift
//  HappyEat
//
//  Created by ctx2016 on 17/1/13.
//  Copyright © 2017年 陌路是我. All rights reserved.
//

import UIKit

enum MineDiangDanType{
    case goingType
    case noRushType
    case luckRecoderType
}

class MineDingDanCell: UITableViewCell {
    
    var spImageView:UIImageView = UIImageView.init()
    
    var leftIcon:UIImageView = UIImageView.init()
    
    var nameLabel:UILabel = UILabel.init()
    
    var qhLabel:UILabel = UILabel.init()
    
    var joinLabel:UILabel = UILabel.init()
    
    var againButton:UIButton = UIButton.init()
    
    var winerLabel:UILabel = UILabel.init()
    
    var dateLabel:UILabel = UILabel.init()
    
    var dingdanTYpe:MineDiangDanType?{
        didSet{
            self.setUI()
        }
    }
    var dataDic:[String:String]?{
        didSet{
            if self.dingdanTYpe == .goingType{
                self.leftIcon.snp.makeConstraints({ (make) in
                    make.left.equalTo(0)
                    make.top.equalTo(12)
                    make.size.equalTo(CGSize.init(width: 50, height: 18))
                })
                self.spImageView.snp.makeConstraints({ (make) in
                    make.left.equalTo(16)
                    make.top.equalTo(self.leftIcon.snp.bottom).offset(12)
                    make.size.equalTo(CGSize.init(width: 100, height: 75))
                })
                self.nameLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.spImageView.snp.right).offset(12)
                    make.top.equalTo(self.spImageView)
                    make.right.equalTo(-16)
                    make.height.equalTo(16)
                })
                self.qhLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.nameLabel)
                    make.top.equalTo(self.nameLabel.snp.bottom).offset(10)
                    make.right.equalTo(-16)
                    make.height.equalTo(14)
                })
                self.joinLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.spImageView.snp.right).offset(12)
                    make.height.equalTo(14)
                    make.right.equalTo(-16)
                    make.top.equalTo(self.qhLabel.snp.bottom).offset(10)
                })
            }else if dingdanTYpe == .noRushType{
                self.leftIcon.snp.makeConstraints({ (make) in
                    make.left.equalTo(0)
                    make.top.equalTo(12)
                    make.size.equalTo(CGSize.init(width: 50, height: 18))
                })
                self.spImageView.snp.makeConstraints({ (make) in
                    make.left.equalTo(16)
                    make.top.equalTo(self.leftIcon.snp.bottom).offset(12)
                    make.size.equalTo(CGSize.init(width: 100, height: 75))
                })
                self.nameLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.spImageView.snp.right).offset(12)
                    make.top.equalTo(self.spImageView)
                    make.right.equalTo(-16)
                    make.height.equalTo(16)
                })
                self.qhLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.nameLabel)
                    make.top.equalTo(self.nameLabel.snp.bottom).offset(10)
                    make.right.equalTo(-16)
                    make.height.equalTo(14)
                })
                self.joinLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.spImageView.snp.right).offset(12)
                    make.height.equalTo(14)
                    make.right.equalTo(-16)
                    make.top.equalTo(self.qhLabel.snp.bottom).offset(10)
                })
                self.winerLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.nameLabel)
                    make.height.equalTo(14)
                    make.right.equalTo(-16)
                    make.top.equalTo(self.joinLabel.snp.bottom).offset(10)
                })
                self.dateLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.nameLabel)
                    make.top.equalTo(self.winerLabel.snp.bottom).offset(10)
                    make.height.equalTo(14)
                    make.right.equalTo(-16)
                })
                self.againButton.snp.makeConstraints({ (make) in
                    make.right.equalTo(-16)
                    make.size.equalTo(CGSize.init(width: 80, height: 40))
                    make.top.equalTo(12)
                })
            }
            else{
                self.leftIcon.snp.makeConstraints({ (make) in
                    make.left.equalTo(0)
                    make.top.equalTo(12)
                    make.size.equalTo(CGSize.init(width: 50, height: 18))
                })
                self.spImageView.snp.makeConstraints({ (make) in
                    make.left.equalTo(16)
                    make.top.equalTo(self.leftIcon.snp.bottom).offset(12)
                    make.size.equalTo(CGSize.init(width: 100, height: 75))
                })
                self.nameLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.spImageView.snp.right).offset(12)
                    make.top.equalTo(self.spImageView)
                    make.right.equalTo(-16)
                    make.height.equalTo(16)
                })
                self.qhLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.nameLabel)
                    make.top.equalTo(self.nameLabel.snp.bottom).offset(10)
                    make.right.equalTo(-16)
                    make.height.equalTo(14)
                })
                self.joinLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.spImageView.snp.right).offset(12)
                    make.height.equalTo(14)
                    make.right.equalTo(-16)
                    make.top.equalTo(self.qhLabel.snp.bottom).offset(10)
                })
                self.winerLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.nameLabel)
                    make.height.equalTo(14)
                    make.right.equalTo(-16)
                    make.top.equalTo(self.joinLabel.snp.bottom).offset(10)
                })
                self.dateLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.nameLabel)
                    make.top.equalTo(self.winerLabel.snp.bottom).offset(10)
                    make.height.equalTo(14)
                    make.right.equalTo(-16)
                })
                self.againButton.snp.makeConstraints({ (make) in
                    make.right.equalTo(-16)
                    make.size.equalTo(CGSize.init(width: 80, height: 40))
                    make.top.equalTo(12)
                })
            }
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}
extension MineDingDanCell {
    func setUI(){
        switch self.dingdanTYpe! {
        case .goingType:
            self.contentView.addSubview(self.leftIcon)
            self.contentView.addSubview(self.spImageView)
            self.contentView.addSubview(self.nameLabel)
            self.contentView.addSubview(self.qhLabel)
            self.contentView.addSubview(self.joinLabel)
            self.nameLabel.font = UIFont.systemFont(ofSize: 16)
            self.qhLabel.font = UIFont.systemFont(ofSize: 14)
            self.joinLabel.font = UIFont.systemFont(ofSize: 14)
            self.qhLabel.textColor = BaseFontColor
            self.joinLabel.textColor = BaseFontColor
            self.leftIcon.image = UIImage.init(named: "jinxingzhong")
            break
        case .luckRecoderType:
            self.contentView.addSubview(self.leftIcon)
            self.contentView.addSubview(self.spImageView)
            self.contentView.addSubview(self.nameLabel)
            self.contentView.addSubview(self.qhLabel)
            self.contentView.addSubview(self.joinLabel)
            self.contentView.addSubview(self.winerLabel)
            self.contentView.addSubview(self.dateLabel)
            self.contentView.addSubview(self.againButton)
            self.nameLabel.font = UIFont.systemFont(ofSize: 16)
            self.qhLabel.font = UIFont.systemFont(ofSize: 14)
            self.joinLabel.font = UIFont.systemFont(ofSize: 14)
            self.winerLabel.font = UIFont.systemFont(ofSize: 14)
            self.dateLabel.font = UIFont.systemFont(ofSize: 14)
            self.qhLabel.textColor = BaseFontColor
            self.joinLabel.textColor = BaseFontColor
            self.winerLabel.textColor = BaseFontColor
            self.dateLabel.textColor = BaseFontColor
            self.againButton.addTarget(self, action: #selector(againButtonAction), for: .touchUpInside)
            self.againButton.setTitle("再次参与", for: .normal)
            self.againButton.backgroundColor = .red
            self.againButton.layer.cornerRadius = 5.0
            self.leftIcon.image = UIImage.init(named: "weiqiangzhong")
            break
        default:
            self.contentView.addSubview(self.leftIcon)
            self.contentView.addSubview(self.spImageView)
            self.contentView.addSubview(self.nameLabel)
            self.contentView.addSubview(self.qhLabel)
            self.contentView.addSubview(self.joinLabel)
            self.contentView.addSubview(self.winerLabel)
            self.contentView.addSubview(self.dateLabel)
            self.contentView.addSubview(self.againButton)
            self.nameLabel.font = UIFont.systemFont(ofSize: 16)
            self.qhLabel.font = UIFont.systemFont(ofSize: 14)
            self.joinLabel.font = UIFont.systemFont(ofSize: 14)
            self.winerLabel.font = UIFont.systemFont(ofSize: 14)
            self.dateLabel.font = UIFont.systemFont(ofSize: 14)
            self.qhLabel.textColor = BaseFontColor
            self.joinLabel.textColor = BaseFontColor
            self.winerLabel.textColor = BaseFontColor
            self.dateLabel.textColor = BaseFontColor
            self.againButton.addTarget(self, action: #selector(againButtonAction), for: .touchUpInside)
            self.againButton.setTitle("再次参与", for: .normal)
            self.againButton.backgroundColor = .red
            self.againButton.layer.cornerRadius = 5.0
            self.leftIcon.image = UIImage.init(named: "weiqiangzhong")
            break
        }
    }
    //再次购买按钮事件
    func againButtonAction(){
        print("againButtonAction")
        }
}
